"""Definition of the CollaborationArea content type
"""

from zope.interface import implements, directlyProvides

from Products.Archetypes import atapi
from Products.ATContentTypes.content import folder
from Products.ATContentTypes.content import schemata
from Products.CMFPlone.utils import getToolByName


from utpocf.communityofpractice import communityofpracticeMessageFactory as _
from utpocf.communityofpractice.interfaces import ICollaborationArea
from utpocf.communityofpractice.config import PROJECTNAME

CollaborationAreaSchema = folder.ATFolderSchema.copy() + atapi.Schema((

    # -*- Your Archetypes field definitions here ... -*-

))

# Set storage on fields copied from ATFolderSchema, making sure
# they work well with the python bridge properties.

CollaborationAreaSchema['title'].storage = atapi.AnnotationStorage()
CollaborationAreaSchema['description'].storage = atapi.AnnotationStorage()

schemata.finalizeATCTSchema(CollaborationAreaSchema, folderish=True, moveDiscussion=False)

class CollaborationArea(folder.ATFolder):
    """Container for collaboration services for CoP"""
    implements(ICollaborationArea)

    portal_type = "CollaborationArea"
    schema = CollaborationAreaSchema

    title = atapi.ATFieldProperty('title')
    description = atapi.ATFieldProperty('description')


    def getRecent(self,limit=5):
        catalog = getToolByName(self,'portal_catalog')
        path = '/'.join(self.getPhysicalPath())+'/wiki'
        results = catalog(path=path,portal_type='Document',
                          sort_on='Date',
                          sort_order='descending',
                          sort_limit=limit)[:limit]

        return results 
        


atapi.registerType(CollaborationArea, PROJECTNAME)
